package org.tis.tools.abf.module.ac.controller;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.tis.tools.abf.module.ac.controller.request.AcOperatorConfigRequest;
import org.tis.tools.abf.module.ac.entity.AcOperatorConfig;
import org.tis.tools.abf.module.ac.service.IAcOperatorConfigService;
import org.tis.tools.core.web.controller.BaseController;
import org.tis.tools.core.web.vo.SmartPage;
import org.tis.tools.model.common.ResultVO;
import org.tis.tools.model.log.enums.OperateType;
import org.tis.tools.starter.operatelog.annotation.OperateLog;

import javax.validation.constraints.NotBlank;

/**
 * acOperatorConfig的Controller类
 * 操作员个性配置
 * @author Auto Generate Tools
 * @date 2018/04/23
 */
@RestController
@Validated
@RequestMapping("/acOperatorConfig")
@Slf4j
public class AcOperatorConfigController extends BaseController<AcOperatorConfig>  {

    @Autowired
    private IAcOperatorConfigService acOperatorConfigService;

    @OperateLog(type = OperateType.ADD,desc = "新增操作员个性配置")
    @ApiOperation(value = "新增操作员个性配置", notes = "传入AcOperatorConfigRequest作为参数")
    @PostMapping
    public ResultVO add(@RequestBody @Validated @ApiParam(value = "AcOperatorConfigRequest",name = "传入的AcOperatorConfigRequest类",required = true) AcOperatorConfigRequest acOperatorConfig) {
        acOperatorConfigService.add(acOperatorConfig);
        return ResultVO.success("新增成功！");
    }

    @OperateLog(type = OperateType.UPDATE,desc = "修改操作员个性配置")
    @ApiOperation(value = "修改操作员个性配置", notes = "传入AcOperatorConfigRequest作为参数")
    @PutMapping
    public ResultVO update(@RequestBody @Validated @ApiParam(value = "AcOperatorConfigRequest",name = "传入的AcOperatorConfigRequest类",required = true) AcOperatorConfigRequest acOperatorConfigRequest) {
        AcOperatorConfig acOperatorConfig = acOperatorConfigService.selectById(acOperatorConfigRequest.getGuid());
        if (acOperatorConfig == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        acOperatorConfig = acOperatorConfigService.change(acOperatorConfigRequest);
        return ResultVO.success("修改成功！",acOperatorConfig);
    }

    @OperateLog(type =OperateType.DELETE,desc = "删除操作员个性配置")
    @ApiOperation(value = "删除操作员个性配置", notes = "传入操作员个性化配置GUID作为参数")
    @DeleteMapping("/{id}")
    public ResultVO delete(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员个性化配置GUID",required = true) String id) {
        AcOperatorConfig acOperatorConfig = acOperatorConfigService.selectById(id);
        if (acOperatorConfig == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        acOperatorConfigService.deleteOperatorConfig(id);
        return ResultVO.success("删除成功");
    }

    @ApiOperation(value = "根据GUID查询操作员个性化配置", notes = "传入操作员个性化配置GUID作为参数")
    @GetMapping("/{id}")
    public ResultVO detail(@PathVariable @NotBlank(message = "id不能为空") @ApiParam(value = "id",name = "操作员个性化配置GUID",required = true) String id) {
        AcOperatorConfig acOperatorConfig = acOperatorConfigService.selectById(id);
        if (acOperatorConfig == null) {
            return ResultVO.error("404", "找不到对应记录或已经被删除！");
        }
        return ResultVO.success("查询成功", acOperatorConfig);
    }

    @ApiOperation(value = "分页查询操作员个性化配置", notes = "传入page,condition作为参数")
    @PostMapping("/list")
    public ResultVO list(@RequestBody @Validated @ApiParam(value = "page",name = "传入查询的page和condition",required = true) SmartPage<AcOperatorConfig> page) {
        return  ResultVO.success("查询成功", acOperatorConfigService.selectPage(getPage(page), getCondition(page)));
    }
    
}

